package com.changgou.controller;

import com.changgou.goods.pojo.Brand;
import com.changgou.service.impl.BrandServiceImpl;
import entity.ResBean;
import entity.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 李民康
 * @date 2022/1/10 14:38
 */
@RestController
@Api(value = "serice-goods模块",tags = "品牌Controller")
@RequestMapping("/brand")
@CrossOrigin//允许跨域访问  A域名访问B域名的数据
public class BrandController {

    @Autowired
    private BrandServiceImpl brandService;

    /**
     * 查询所有品牌
     */
    @GetMapping
    @ApiOperation("查询所有品牌")
    public ResBean findAll() {
        return ResBean.success("查询所有品牌成功", StatusCode.OK,brandService.findAll());
    }

    /**
     * 根据id查询品牌
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询品牌")
    public ResBean findById(@PathVariable("id") Integer id) {
        return ResBean.success("根据id查询品牌成功",brandService.findById(id));
    }

    /**
     * 增加品牌
     */
    @PostMapping()
    @ApiOperation("增加品牌")
    public ResBean findById(@RequestBody Brand brand) {
        brandService.add(brand);
        return ResBean.success("增加品牌成功");
    }

    /**
     * 修改品牌
     */
    @PutMapping()
    @ApiOperation("修改品牌")
    public ResBean update(@RequestBody Brand brand) {
        brandService.update(brand);
        return ResBean.success("修改品牌成功");
    }

    /**
     * 根据id删除品牌
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除品牌")
    public ResBean update(@PathVariable("id") Integer id) {
        brandService.delete(id);
        return ResBean.success("删除品牌成功");
    }

    /**
     * 条件查询
     * @param brand
     * @return
     */
    @PostMapping("/search")
    @ApiOperation("条件查询")
    public ResBean findList(@RequestBody Brand brand) {
        return ResBean.success("条件查询成功",brandService.findList(brand));
    }

    /**
     * 分页查询
     * @return
     */
    @GetMapping("/search/{page}/{size}")
    @ApiOperation("分页查询")
    public ResBean findPage(@PathVariable("page")Integer page, @PathVariable("size")Integer size) {
        return ResBean.success("分页查询",brandService.findPage(page,size));
    }

    /**
     * 条件分页查询
     * @return
     */
    @PostMapping("/search/{page}/{size}/")
    @ApiOperation("条件分页查询")
    public ResBean findPage(@RequestBody Brand brand,@PathVariable("page")Integer page, @PathVariable("size")Integer size) {
        return ResBean.success("分页查询",brandService.findPage(brand,page,size));
    }



}
















